<template>
    <div>
        <!--      搜索  创建-->
        <el-form :inline="true" :model="form" class="demo-form-inline">
            <el-form-item>
                <el-input clearable v-model="form.name" style="width: 300px" placeholder="姓名"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="query">搜索</el-button>
            </el-form-item>
            <el-form-item>
                <el-button type="success" @click="create">创建</el-button>
            </el-form-item>
        </el-form>
        <!--           11 列表-->
     <!--    <el-tabs v-model="activeName" @tab-click="handleClick">
            <el-tab-pane label="登记列表" name="first">用户管理</el-tab-pane>
            <el-tab-pane label="转件列表" name="second">配置管理</el-tab-pane>
        </el-tabs> -->
        <el-table :data="tableData" border>
            <el-table-column
                    fixed
                    prop="name"
                    label="姓名"
                    align="center"
                    width="150">
            </el-table-column>
            <el-table-column
                    prop="sex"
                    label="性别"
                    align="center"
                    width="105">
                <template slot-scope="scope">
                    <span v-if="scope.row.sex == '0'">男</span>
                    <span v-if="scope.row.sex == '1'">女</span>
                </template>
            </el-table-column>
            <el-table-column
                    prop="education"
                    label="教育程度"
                    align="center"
                    width="200">
            </el-table-column>
            <el-table-column
                    prop="tel"
                    label="联系电话"
                    align="center"
                    width="200">
            </el-table-column>
            <el-table-column
                    prop="state"
                    label="状态"
                    align="center"
                    width="150">
                <template slot-scope="scope">
                    <span v-if="scope.row.state == '0'">未办结</span>
                    <span v-if="scope.row.state == '1'">已转办</span>
                    <span v-if="scope.row.state == '2'">已办结</span>
                    <span v-if="scope.row.state == '3'">已退回</span>
                </template>
            </el-table-column>
            <el-table-column
                    fixed="right"
                    label="操作"
                    align="center"
                    width="300">
                <template slot-scope="scope">
                    <el-button
                            v-show="scope.row.state !== '2'"
                            type="success"
                            size="mini"
                            @click="handleEdit(scope.row)">编辑
                    </el-button>
                    <el-button
                            v-show="scope.row.state === '2'"
                            type="info"
                            size="mini"
                            @click="info(scope.row)">详情
                    </el-button>
                    <el-button
                            v-show="scope.row.state === '0'"
                            type="primary"
                            size="mini"
                            @click="transfer(scope.row)">转办
                    </el-button>
                    <el-button
                            v-show="scope.row.state==='1'"
                            type="info"
                            size="mini">已转办
                    </el-button>
                    <el-button
                            v-show="scope.row.state==='0'"
                            type="danger"
                            size="mini"
                            @click="handleDelete(scope.row)">删除
                    </el-button>
                </template>
            </el-table-column>
        </el-table>
<!--        分页-->
        <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="pageNo"
                :page-sizes="[10, 20, 50, 100]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next"
                :total="totalRecord" class="text-center mt10">
        </el-pagination>
<!--        创建弹出框-->
        <el-dialog title="创建" :visible.sync="dialogFormVisible">
            <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="180px" class="demo-ruleForm">
                <el-form-item label="姓名:" prop="name">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleForm.name"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="性别" prop="sex">
                    <el-select style="width: 320px;margin-left: 10px" v-model="ruleForm.sex" placeholder="请选择">
                        <el-option label="男" value="0">男</el-option>
                        <el-option label="女" value="1">女</el-option>
                    </el-select>
                </el-form-item>
                <el-form-item label="出生日期:" prop="birth">
                    <div style="width: 320px;margin-left: 10px">
                        <!-- <el-input v-model="ruleForm.birth"></el-input> -->
                        <el-date-picker
                            style="width: 320px"
                            v-model="ruleForm.birth"
                            type="date"
                            placeholder="选择日期">
                        </el-date-picker>
                    </div>
                </el-form-item>
                <el-form-item label="教育程度:" prop="education">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleForm.education"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="民族:" prop="nation">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleForm.nation"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="家庭住址:" prop="address">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleForm.address"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="身份证号:" prop="idcard">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleForm.idcard"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="联系电话:" prop="tel">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleForm.tel"></el-input>
                    </div>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisible = false">取 消</el-button>
                <el-button type="primary" @click="sure">确 定</el-button>
            </div>
        </el-dialog>

<!--        修改弹出框-->
        <el-dialog title="修改" :visible.sync="dialogFormVisibleEdit">
            <el-form :model="ruleFormEdit" :rules="rulesEdit" ref="ruleForm" label-width="180px" class="demo-ruleForm">
                <el-form-item label="姓名:" prop="name">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.name"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="性别:" prop="sex">
                    <div style="width: 320px;margin-left: 10px">
                        <!-- <el-input v-model="ruleFormEdit.sex"></el-input> -->
                        <el-select style="width: 320px" v-model="ruleFormEdit.sex" placeholder="请选择">
                            <el-option label="男" value="0">男</el-option>
                            <el-option label="女" value="1">女</el-option>
                        </el-select>
                    </div>
                </el-form-item>
                <el-form-item label="出生日期:" prop="birth">
                    <div style="width: 320px;margin-left: 10px">
                        <!-- <el-input v-model="ruleFormEdit.birth"></el-input> -->
                        <el-date-picker
                            style="width: 320px"
                            v-model="ruleFormEdit.birth"
                            type="date"
                            placeholder="选择日期">
                        </el-date-picker>

                    </div>
                </el-form-item>
                <el-form-item label="教育程度:" prop="education">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.education"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="民族:" prop="nation">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.nation"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="家庭住址:" prop="address">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.address"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="身份证号:" prop="idcard">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.idcard"></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="联系电话:" prop="tel">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.tel"></el-input>
                    </div>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button @click="dialogFormVisibleEdit = false">取 消</el-button>
                <el-button type="primary" @click="yes">确 定</el-button>
            </div>
        </el-dialog>

        <!--   详情弹出框-->
        <el-dialog title="详情" :visible.sync="dialogFormVisibleEdit1">
            <el-form :model="ruleFormEdit" :rules="rulesEdit" ref="ruleForm" label-width="180px" class="demo-ruleForm">
                <el-form-item label="姓名:" prop="name">
                    <!-- {{ruleFormEdit.name}} -->
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.name" readonly></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="性别:" prop="sex">
                    <div style="width: 320px;margin-left: 10px">
                        <!-- <el-input v-model="ruleFormEdit.sex"></el-input> -->
                        <el-select style="width: 320px" v-model="ruleFormEdit.sex" placeholder="请选择" readonly>
                            <el-option label="男" value="0">男</el-option>
                            <el-option label="女" value="1">女</el-option>
                        </el-select>
                    </div>
                </el-form-item>
                <el-form-item label="出生日期:" prop="birth">
                    <div style="width: 320px;margin-left: 10px">
                        <!-- <el-input v-model="ruleFormEdit.birth"></el-input> -->
                        <el-date-picker
                            readonly="readonly"
                            style="width: 320px"
                            v-model="ruleFormEdit.birth"
                            type="date"
                            placeholder="选择日期">
                        </el-date-picker>

                    </div>
                </el-form-item>
                <el-form-item label="教育程度:" prop="education">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.education" readonly></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="民族:" prop="nation">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.nation" readonly></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="家庭住址:" prop="address">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.address" readonly></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="身份证号:" prop="idcard">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.idcard" readonly></el-input>
                    </div>
                </el-form-item>
                <el-form-item label="联系电话:" prop="tel">
                    <div style="width: 320px;margin-left: 10px">
                        <el-input v-model="ruleFormEdit.tel" readonly></el-input>
                    </div>
                </el-form-item>
            </el-form>
            <div slot="footer" class="dialog-footer">
                <el-button type="primary" @click="dialogFormVisibleEdit1 = false">关 闭</el-button>
            </div>
        </el-dialog>
    </div>
</template>

<script>


    export default {

        name: 'test',

        data() {
            return {
                activeName:'first',
                tableData: [],
                pageNo: 1,
                pageSize: 10,
                totalRecord: 0,
                totalPage: 0,
                dialogFormVisible: false, //创建弹出框
                dialogFormVisibleEdit:false, //修改弹出框
                dialogFormVisibleEdit1:false,//详情弹出框
                form:{},  //创建按钮的表单
                //创建表单
                ruleForm: {},
                //修改表单
                ruleFormEdit:{},
                //验证
                rules: {
                    name: [
                        { required: true, message: '请输入标题', trigger: 'blur' }
                    ],
                    sex: [
                        { required: true, message: '请输入性别', trigger: 'blur' }
                    ],
                    birth: [
                        { required: true, message: '请输入出生日期', trigger: 'blur' }
                    ],
                    address: [
                        { required: true, message: '请输入家庭住址', trigger: 'blur' }
                    ],

                    education: [
                        { required: true, message: '请输入教育程度', trigger: 'blur' }
                    ],
                    nation: [
                        { required: true, message: '请输入民族', trigger: 'blur' }
                    ],
                    idcard: [
                        { required: true, message: '请输入身份证号', trigger: 'blur' }
                    ],
                    tel: [
                        { required: true, message: '请输入联系电话', trigger: 'blur' }
                    ],
                },
                //修改验证
                rulesEdit: {
                    name: [
                        { required: true, message: '请输入标题', trigger: 'blur' }
                    ],
                    sex: [
                        { required: true, message: '请输入性别', trigger: 'blur' }
                    ],
                    birth: [
                        { required: true, message: '请输入出生日期', trigger: 'blur' }
                    ],
                    address: [
                        { required: true, message: '请输入家庭住址', trigger: 'blur' }
                    ],

                    education: [
                        { required: true, message: '请输入教育程度', trigger: 'blur' }
                    ],
                    nation: [
                        { required: true, message: '请输入民族', trigger: 'blur' }
                    ],
                    idcard: [
                        { required: true, message: '请输入内容', trigger: 'blur' }
                    ],
                    tel: [
                        { required: true, message: '请输入身份证号', trigger: 'blur' }
                    ],
                },
                formLabelWidth: '120px',
                cid:''
            }
        },

        props: {},

        components: {},

        computed: {},

        methods: {
            // 初始化
            async init() {
                const res = await this.$http('selecteventlist',{
                    pageNo: this.pageNo,
                    pageSize: this.pageSize
                })
                this.tableData = res.results
                console.log('res',this.tableData)
                this.totalPage = res.totalPage;
                this.totalRecord = res.totalRecord;
                console.log(res)
            },
            handleClick(row) {
                console.log(row);
            },
            //分页
            async handleSizeChange(val) {
                this.pageSize = val;
                this.init();
            },
            async handleCurrentChange(val) {
                this.pageNo = val;
                this.init();
            },
            //创建
            create() {
                this.dialogFormVisible = true
                this.ruleForm.title = ""
                this.ruleForm.content = ""
            },
            //点击确定立即创建
            async sure(){
                //console.log('sex',this.ruleForm.sex)
                var timestamp = this.ruleForm.birth;
                //console.log('birth',timestamp)
                var d = new Date(timestamp);    //根据时间戳生成的时间对象
                var date = (d.getFullYear()) + "-" +
                    (d.getMonth() + 1) + "-" +
                    (d.getDate())
                this.ruleForm.birth = date
                console.log('shijian',this.ruleForm.birth)
                // if(this.ruleForm.name){
                //
                // }
                const res = await this.$http('createorder',{
                    name:this.ruleForm.name,
                    sex:this.ruleForm.sex,
                    birth:this.ruleForm.birth,
                    education:this.ruleForm.education,
                    nation:this.ruleForm.nation,
                    address:this.ruleForm.address,
                    idcard:this.ruleForm.idcard,
                    tel:this.ruleForm.tel
                })
                //this.dialogFormVisible = false
                if (res.count === 1) {
                    this.$message({
                        message: '创建成功',
                        type: 'success'
                    });
                    this.dialogFormVisible = false
                    this.init()
                    this.ruleForm = {}
                } else {
                    this.$message({
                        message: '创建失败',
                        type: 'error'
                    });
                }
            },
            info(row){
                this.dialogFormVisibleEdit1 = true
                this.ruleFormEdit = row
            },
            //编辑
            handleEdit(row){
                this.dialogFormVisibleEdit = true
                this.cid = row.id
                this.ruleFormEdit = row
            },
            //点击确定即可完成编辑
            async yes(){
                var timestamp = this.ruleFormEdit.birth;
                console.log('birth',timestamp)
                var d = new Date(timestamp);    //根据时间戳生成的时间对象
                var date = (d.getFullYear()) + "-" +
                    (d.getMonth() + 1) + "-" +
                    (d.getDate())
                this.ruleFormEdit.birth = date
                const res = await this.$http('createorder',{
                    id:this.cid,
                    name:this.ruleFormEdit.name,
                    sex:this.ruleFormEdit.sex,
                    birth:this.ruleFormEdit.birth,
                    education:this.ruleFormEdit.education,
                    nation:this.ruleFormEdit.nation,
                    address:this.ruleFormEdit.address,
                    idcard:this.ruleFormEdit.idcard,
                    tel:this.ruleFormEdit.tel
                })
                //this.dialogFormVisibleEdit = false
                if (res.count === 1) {
                    this.$message({
                        message: '编辑成功',
                        type: 'success'
                    });
                    this.dialogFormVisibleEdit = false
                    this.init()
                } else {
                    this.$message({
                        message: '编辑失败',
                        type: 'error'
                    });
                }
            },
            //删除
            async handleDelete(row){
                this.$confirm('将永久删除该内容, 是否继续?', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(async () => {
                    const res =await this.$http('createorder',{
                        id:row.id,
                        del_flag:'1'
                    })
                    this.init()
                    this.$message({
                        type: 'success',
                        message: '删除成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            },
            //转件
            async transfer(row){
                this.$confirm('是否确认转件?', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(async () => {
                    const res =await this.$http('updateEvnState',{
                        id:row.id,
                    })
                    this.init()
                    this.$message({
                        type: 'success',
                        message: '转件成功!'
                    });
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消转件'
                    });
                });
            },
            //搜索
            async query(){
                const res = await this.$http('selecteventlist',{
                    name:this.form.name
                })
                this.tableData = res.results
                this.totalPage = res.totalPage;
                this.totalRecord = res.totalRecord;
            }
        },

        watch: {},

        mounted() {
            this.init();
        },

    }
</script>

<style scoped>

</style>
